package com.dscyy.readutil;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import com.ecbt.rest.util.FileUtil;


public class ReadTmData {
	public static void main(String[] args) throws Exception {
		Class.forName("oracle.jdbc.OracleDriver");
		Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@118.178.86.19:1521/orcl", "czlis",
				"junaiTAO1!");
		Statement stmt = conn.createStatement();
		String sql = "select l.oper,l.info,l.opertime,l.oper_data_all from sys_log l where l.oper like '上传天马深圳%' and l.info like '成功箱号%' and l.operdate>='20240301' order by id asc";
		ResultSet rset = stmt.executeQuery(sql);
		while(rset.next()) {
			String jsonData = rset.getString(4);
			String boxName = rset.getString(2).substring(5);
			String oper = rset.getString(1);
			if(oper.contains("黑")) {
				boxName = boxName + "_黑名单";
			}
			
			String dirPath = "D:\\AijunTao\\Desktop\\TM";
    		File outputFile = new File(dirPath+File.separator+boxName+".json");  
    		byte[] data = jsonData.getBytes();
			FileUtil.createFile(outputFile, data);
			
		}
		rset.close();
		stmt.close();
		conn.close();
	}
}
